#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@File    :   is_ipv4_or_ipv6.py    
@Contact :   291622538@qq.com

@Modify Time      @Author    @Version    @Description
------------      -------    --------    -----------
2021/3/31 19:03   fan        1.0         None
"""
from netaddr.ip import IPAddress

addr = None


# 判断是否是ipv4或者ipv6
def is_ip4_or_ip6(cfg_str) -> bool:
    """
    :param cfg_str: ip地址
    :return:    返回是否是标准的ip地址
    """
    global addr
    if '/' in cfg_str:
        text = cfg_str[:cfg_str.rfind('/')]
    else:
        text = cfg_str

    try:
        addr = IPAddress(text)
        ip_flg = True
    except Exception as e:
        print(e)
        ip_flg = False
    return ip_flg


if __name__ == '__main__':
    result = is_ip4_or_ip6("123.213.129.0")
    print(result)
